<template>
  <el-container>
    <!-- aside -->
    <el-aside width="200">
      <h1 class="logo"></h1>
      <el-menu :default-active="$route.path" :collapse="collapse" class="el-qf-menu">
        <qf-sub-menu :sideMenu="sideMenu"> </qf-sub-menu>
      </el-menu>
    </el-aside>
    <el-container>
      <!-- header -->
      <el-header>
        <el-row type="flex" class="row-bg" justify="space-between">
          <el-col :span="6">
            <div class="grid-content left">
              <i
                @click="collapse = !collapse"
                :class="['iconfont', collapse ? 'icon-zhankai' : 'icon-shouqi']"
              ></i>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content center">CRM管理系统</div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content right">
              <el-avatar :size="40" :src="avatarUrl"></el-avatar>
              <b
                >欢迎您:
                <el-dropdown @command="command">
                  <span class="el-dropdown-link nickname">
                    {{ userInfo.nickname
                    }}<i class="el-icon-arrow-down el-icon--right"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item icon="iconfont icon-VIP" command="" divided
                      >vip到期时间:</el-dropdown-item
                    >
                    <el-dropdown-item icon="iconfont icon-VIP" command="" divided
                      >vip充值</el-dropdown-item
                    >
                    <el-dropdown-item
                      icon="iconfont icon-zhanghaoxinxi"
                      divided
                      command="mine"
                      >账号信息</el-dropdown-item
                    >
                    <el-dropdown-item
                      icon="iconfont icon-dingdan"
                      divided
                      command="StudentProduct"
                      >项目管理</el-dropdown-item
                    >
                    <el-dropdown-item
                      icon="iconfont icon-icon"
                      @click.native="quit"
                      divided
                      >退出</el-dropdown-item
                    >
                  </el-dropdown-menu>
                </el-dropdown>
              </b>
              &nbsp; &ensp;
              <!-- <b @click="quit" class="quit">退出</b> -->
            </div>
          </el-col>
        </el-row>
      </el-header>

      <!-- main -->
      <el-main>
        <!-- 面包屑 -->
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item
            :to="{ name: bread.name }"
            v-for="bread in breadCrumb"
            :key="bread.name"
            >{{ bread.meta.name }}</el-breadcrumb-item
          >
        </el-breadcrumb>
        <router-view> </router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState(["userInfo", "sideMenu", "breadCrumb"]),
    avatarUrl() {
      //如果用户没有头像就使用默认头像，如果有就使用用户头像
      return this.userInfo.headimgurl
        ? this.userInfo.headimgurl
        : "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
    },
    mounted() {},
  },
  data() {
    return {
      collapse: false,
    };
  },
  methods: {
    //右上角用户下拉菜单触发事件
    command(routerName) {
      // console.log(c);
      //routerName就是下拉菜单传入的路由名字
      if (routerName) {
        this.$router.push({ name: routerName });
      }
    },
    cancel() {
      this.cancelToken();
      //取消，中断请求
    },
    quit() {
      //退出登录
      //1.清除token
      localStorage.removeItem("qf-token");
      //2.跳转到登录页
      this.$router.push("/login");
      //3.刷新页面
      location.reload();
    },
  },
};
</script>

<style scoped lang="less">
.el-header {
  background: linear-gradient(135deg, rgb(76, 103, 255), rgb(86, 53, 223));
  color: #fff;
  min-height: 60px !important ;
  font-weight: bolder;
  text-align: center;
  line-height: 40px;
  .left {
    text-align: left;
    line-height: 41px;
    i {
      font-size: 35px;
      cursor: pointer;
    }
  }
  .center {
    font-size: 30px;
  }
  .el-avatar {
    vertical-align: middle;
    margin-right: 10px;
  }
  .quit {
    color: deeppink;
    text-decoration: underline;
    cursor: pointer;
  }
  .nickname {
    margin-left: 5px;
    color: #fff;
  }
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 20px;
}

.el-aside {
  background: linear-gradient(135deg, rgb(76, 103, 255), rgb(86, 53, 223));
  color: #333;
  text-align: center;
  // line-height: 200px;
  .logo {
    min-height: 60px;
    // background-color: #fff;
  }
  .subMenu {
    text-align: left;
  }
  /deep/ .el-qf-menu:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
}

.el-main {
  background-color: #fff;
  color: #333;
  text-align: center;
  // line-height: 160px;
}

.el-container {
  margin-bottom: 40px;
  height: 100%;
}

//   .el-container:nth-child(5) .el-aside,
//   .el-container:nth-child(6) .el-aside {
//     line-height: 260px;
//   }

//   .el-container:nth-child(7) .el-aside {
//     line-height: 320px;
//   }

//顶栏laout
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  margin: 10px 0;
  // background-color: #f9fafc;
}
</style>
